package com.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBOpenHelper extends SQLiteOpenHelper {

	private static final String DB_SETTING_TABLE = "setting";
	private static final String DB_HISTORY_TABLE = "history";

	public static final String KEY_ID = "_id";
	public static final String KEY_NAME = "name";
	public static final String KEY_VALUE = "value";

	public static final String HISTORY_KEY_TITLE = "title";
	public static final String HISTORY_KEY_VID = "vid";
	public static final String HISTORY_KEY_IMG = "img";
	public static final String HISTORY_KEY_PLAYTIME = "playtime";
	public static final String HISTORY_KEY_DURATION = "duration";

	private final String DB_SETTING_CREATE = "create table " + DB_SETTING_TABLE
			+ " (" + KEY_ID + " integer primary key autoincrement, " + KEY_NAME
			+ " text, " + KEY_VALUE + " integer);";

	private final String DB_HISTORY_CREATE = "create table " + DB_HISTORY_TABLE
			+ " (" + KEY_ID + " integer primary key autoincrement, "
			+ HISTORY_KEY_TITLE + " text, " + HISTORY_KEY_VID + " text, "
			+ HISTORY_KEY_PLAYTIME + " text, " + HISTORY_KEY_DURATION
			+ " text, " + HISTORY_KEY_IMG + " text);";

	public DBOpenHelper(Context context, String name, CursorFactory factory,
			int version) {
		super(context, name, factory, version);
	}

	@Override
	public void onCreate(SQLiteDatabase _db) {
		_db.execSQL(DB_SETTING_CREATE);
		_db.execSQL(DB_HISTORY_CREATE);
	}

	@Override
	public void onUpgrade(SQLiteDatabase _db, int _oldVersion, int _newVersion) {
		_db.execSQL("DROP TABLE IF EXISTS " + DB_SETTING_TABLE);
		onCreate(_db);
	}

}
